import 'package:flutter/material.dart';
class Login extends StatefulWidget {
  @override
  _LoginState createState() => _LoginState();
}

class _LoginState extends State<Login> {
  GlobalKey _formKey = new GlobalKey<FormState>();
  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width-120;
    TextEditingController _phoneController = new TextEditingController();
    TextEditingController _passwordController = new TextEditingController();
    return Scaffold(
      backgroundColor: Colors.lightBlueAccent,
      body: GestureDetector(
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: SingleChildScrollView(
          child: Center(
            child: Form(
              key: _formKey,
              autovalidate: true,
              child: Column(
                children: <Widget>[
                  SizedBox(height: 100),
                  Image.asset('assets/logo.png', width: 80, height: 94),
                  SizedBox(height: 80),
                  Container(
                    width: width,
                    child: TextFormField(
                      controller: _phoneController,
                      keyboardType: TextInputType.phone,
                      decoration: InputDecoration(
                        labelText: '手机号',
                        hintText: '请输入手机号',
                        prefixIcon: Icon(Icons.person, size: 25, color: Colors.white),
                      ),
                      validator: (v) {
                        return v.trim().isNotEmpty ? '':'手机号不能为空';
                      },
                    ),
                  ),
                  SizedBox(height: 20),
                  Container(
                    width: width,
                    child: TextFormField(
                      controller: _passwordController,
                      obscureText: true,
                      decoration: InputDecoration(
                          labelText: '密码',
                          hintText: '请输入密码',
                          prefixIcon: Icon(Icons.lock, size: 25, color: Colors.white)
                      ),
                    ),
                  ),
                  SizedBox(height: 100),
                  MaterialButton(
                    onPressed: () {
                      print(_phoneController.text);
                      print(_passwordController.text);
                    },
                    minWidth: 200,
                    color: Colors.blue,
                    child: Text('登录', style: TextStyle(color: Colors.white, fontSize: 18)),
                  )
                ],
              ),
            )
          ),
        )
      ),
    );
  }
}
